package com.bifrost.listener;

import com.bifrost.event.CartUpdateEvent;
import com.bifrost.service.JedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
/**
 * @author rangf
 * @date 2018/3/27
 */
@Component
public class CartUpdateListener implements ApplicationListener<CartUpdateEvent> {

    @Autowired
    JedisService jedisService;

    @Override
    public void onApplicationEvent(CartUpdateEvent event) {
        String merchantId = event.getSource().toString();
        String customerId = event.getCustomerId().toString();
        jedisService.del(String.format("customer:carts:cart:%s:%s", customerId, merchantId));
        jedisService.del(String.format("customer:carts:quantity:%s:%s", customerId, merchantId));
    }
}
